#pragma once
#include <xcommonfunc.h>
#include <tinyxml/tinyxml.h>
class CXmlParse
{
public:
	CXmlParse(void) : m_nCloseButtonNum(0), m_nMaximizeButtonNum(0), m_nMinimizeButtonNum(0), m_nButtonNum(0)
	{
	}

	~CXmlParse(void)
	{
	}

	CXmlParse(const CString & strPath) : m_strXMLPath(strPath), m_nCloseButtonNum(0), m_nMaximizeButtonNum(0), m_nMinimizeButtonNum(0), m_nButtonNum(0)
	{

	}


	BOOL LoadAllParam()
	{
		if (m_strXMLPath.IsEmpty() || !::PathFileExists(m_strXMLPath))
		{
			ATLTRACE(_T("path is invalid!"));
			return FALSE;
		}

		USES_CONVERSION;
		TiXmlDocument xmlDoc( W2A(m_strXMLPath) );
		bool bRet = xmlDoc.LoadFile();
		if ( !bRet )
		{
			return FALSE; 
		}

		TiXmlElement *pXmlRootElem = xmlDoc.RootElement();
		CString strValue = pXmlRootElem->Value();
		if (strValue.Compare(A2W("skin")))
		{
			return FALSE;
		}

		m_strSkinPath = CA2T(pXmlRootElem->Attribute("skinpath"), CP_UTF8);
		if (m_strSkinPath.IsEmpty())
		{
			return FALSE;
		}
		//////////////////////////////////////////////////////////////////////////////
		TiXmlElement *pTiElement = NULL;
		pTiElement = pXmlRootElem->FirstChildElement("MainFrame");
		if (pTiElement)
		{
			m_strBackground = m_strSkinPath + _T("\\") + CA2T(pTiElement->Attribute("Background"), CP_UTF8);
			m_strLayer = m_strSkinPath + _T("\\") + CA2T(pTiElement->Attribute("Layer"), CP_UTF8);
			m_strButton	= m_strSkinPath + _T("\\") + CA2T(pTiElement->Attribute("Button"), CP_UTF8);

			pTiElement->Attribute("ButtonNum", &m_nButtonNum);
		}
		//////////////////////////////////////////////////////////////////////////////
		pTiElement = pXmlRootElem->FirstChildElement("TitleBar");
		if (pTiElement)
		{
			m_strTitleClose = m_strSkinPath + _T("\\") + CA2T(pTiElement->Attribute("CloseButton"), CP_UTF8);
			pTiElement->Attribute("CloseButtonNum", &m_nCloseButtonNum);

			m_strTitleMin = m_strSkinPath + _T("\\") + CA2T(pTiElement->Attribute("MinimizeButton"), CP_UTF8);
			pTiElement->Attribute("MinimizeButtonNum", &m_nMinimizeButtonNum);

			m_strTitleMax	= m_strSkinPath + _T("\\") + CA2T(pTiElement->Attribute("MaximizeButton"), CP_UTF8);
			pTiElement->Attribute("MaximizeButtonNum", &m_nMaximizeButtonNum);

			CString strColor = CA2T(pTiElement->Attribute("TextColor"), CP_UTF8);
			m_colorTitleText = ConvertStr2Color(strColor);
		}

		return TRUE;
	}

public:
	CString		m_strBackground;
	CString		m_strLayer;
	CString		m_strButton;

	CString		m_strTitleClose;
	CString		m_strTitleMin;
	CString		m_strTitleMax;

	int			m_nButtonNum;
	int			m_nCloseButtonNum;
	int			m_nMinimizeButtonNum;
	int			m_nMaximizeButtonNum;

	COLORREF	m_colorTitleText;
private:
	CString m_strXMLPath;
	CString m_strSkinPath;


};
